import {createApp} from 'vue';
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
import 'element-plus/theme-chalk/display.css';
import * as elIcons from '@element-plus/icons-vue';
import api from '@/api';
import i18n from '@/assets/locales';
import * as jcxIcons from '@/assets/icons';
import '@/assets/style/style.scss';
import jcxCodeEditor from "@/components/jcxCodeEditor";
import jcxDictTag from "@/components/jcxDictTag";
import jcxFormTable from "@/components/jcxFormTable";
import jcxIconSelect from "@/components/jcxIconSelect";
import jcxImageUpload from "@/components/jcxImageUpload";
import jcxPower from "@/components/jcxPower";
import jcxRenderColumn from "@/components/jcxRenderColumn";
import jcxSearch from "@/components/jcxSearch";
import jcxRole from "@/components/jcxRole";
import jcxTable from "@/components/jcxTable";
import jcxTableBar from "@/components/jcxTableBar";
import jcxTreeFormTable from "@/components/jcxTreeFormTable";
import config from "@/config";
import focus from "@/directives/focus";
import power from "@/directives/power";
import powers from "@/directives/powers";
import role from "@/directives/role";
import roles from "@/directives/roles";
import router from '@/router';
import {store} from '@/store';
import color from '@/utils/color';
import crypto from '@/utils/crypto';
import date from '@/utils/date';
import handler from '@/utils/handler';
import request from "@/utils/request";
import storage from '@/utils/storage';
import tool from '@/utils/tool';
import App from '@/App.vue';

const app = createApp(App);

app.use(ElementPlus);
app.use(i18n);
app.use(router);
app.use(store);

// 挂载全局对象
app.config.globalProperties.$api = api;
app.config.globalProperties.$API = api;
app.config.globalProperties.$config = config;
app.config.globalProperties.$CONFIG = config;
app.config.globalProperties.$color = color;
app.config.globalProperties.$COLOR = color;
app.config.globalProperties.$crypto = crypto;
app.config.globalProperties.$CRYPTO = crypto;
app.config.globalProperties.$date = date;
app.config.globalProperties.$DATE = date;
app.config.globalProperties.$request = request;
app.config.globalProperties.$REQUEST = request;
app.config.globalProperties.$storage = storage;
app.config.globalProperties.$STORAGE = storage;
app.config.globalProperties.$tool = tool;
app.config.globalProperties.$TOOL = tool;

// 注册全局组件
app.component('jcxCodeEditor', jcxCodeEditor);
app.component('jcxDictTag', jcxDictTag);
app.component('jcxFormTable', jcxFormTable);
app.component('jcxIconSelect', jcxIconSelect);
app.component('jcxImageUpload', jcxImageUpload);
app.component('jcxPower', jcxPower);
app.component('jcxRenderColumn', jcxRenderColumn);
app.component('jcxSearch', jcxSearch);
app.component('jcxRole', jcxRole);
app.component('jcxTable', jcxTable);
app.component('jcxTableBar', jcxTableBar);
app.component('jcxTreeFormTable', jcxTreeFormTable);

// 统一注册 el-icon 图标
for (let icon in elIcons) {
    app.component(`ElIcon${icon}`, elIcons[icon]);
}

// 统一注册 jcx-icon 图标
for (let icon in jcxIcons) {
    app.component(`JcxIcon${icon}`, jcxIcons[icon]);
}

// 注册全局指令
app.directive('focus', focus);
app.directive('power', power);
app.directive('powers', powers);
app.directive('role', role);
app.directive('roles', roles);

// 关闭 async-validator 全局控制台警告
window.ASYNC_VALIDATOR_NO_WARNING = 1;

// 全局代码错误捕捉
app.config.errorHandler = handler;

// 挂载 app
app.mount('#app');
